using Admin2024.Application.Contracts.FileUpload;
using Admin2024.Application.FileUpload;
using Admin2024.Domain.ObjValue;
using Microsoft.AspNetCore.Mvc;

namespace Admin2024.Api.Controller;
[ApiController]
public class FilesController : ControllerBase
{
    private readonly IAppFileUploadService _appFileUploadService;
    public FilesController(IAppFileUploadService appFileUploadService){
        _appFileUploadService = appFileUploadService;
    }

    [HttpGet("/api/GetFileById/{id}")]
    public async Task<FileContentResult?> Get(Guid id){
        var res = await _appFileUploadService.GetFileByIdAsync(id);
        if(res.IsSuccess){
            return res.Data;
        }else{
            return null;
        }
    }

    [HttpPost("/api/PostFile")]
    public async Task<DomainResult<FileUploadDto>> Post(IFormFile file){
        var res = await _appFileUploadService.UploadFilesAsync(file);
        
        return res;
    }
}